/*
 * @Author: 简随 7405382+liudechao123@user.noreply.gitee.com
 * @Date: 2024-11-10 20:55:35
 * @LastEditors: 简随 7405382+liudechao123@user.noreply.gitee.com
 * @LastEditTime: 2024-11-17 00:08:53
 * @FilePath: \undefinedf:\flash\flash\drv_flash.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/**
 * @file drv_flash.h
 * @author your name (you@domain.com)
 * @brief 
 * @version 0.1
 * @date 2024-11-17
 * 
 * @copyright Copyright (c) 2024
 * 
 */
#ifndef _DRV_FLASH_H
#define _DRV_FLASH_H
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>

/**
 * @brief flash信息
 * 
 */
typedef struct
{
	uint32_t ChipID;		/* 芯片ID */
	uint32_t TotalSize;		/* 芯片容量 字节 */
	uint8_t *cache_buff;	/* 缓存 */
	uint16_t SectorSize;	/* 扇区大小 */
	uint16_t cache_size;	/* 缓存大小 */
	uint8_t  ChipName[16];	/* 芯片名字 */
}flash_inf_def;

/**
 * @brief flash接口
 * 
 */
typedef struct
{
	bool (*drv_flash_erase_sector)(uint32_t _uiSectorAddr);
	bool (*drv_flash_page_write)(uint8_t * _pBuf, uint32_t _uiWriteAddr, uint16_t _usSize);
	bool (*drv_flash_read_buffer)(uint8_t * _pBuf, uint32_t _uiReadAddr, uint32_t _uiSize);
	uint32_t (*drv_flash_lock)(void);
	uint32_t (*drv_flash_unlock)(uint32_t level);
}flash_ops_def;

#define DRV_FLASH_LOG(...)		//printf(__VA_ARGS__)	//打印
#define FLASH_CMP_BUF 			8	//数据比较缓存，影响比较效率
#define FLASH_REWRITE			2	//写入失败后重写次数

int drv_flash_erase_sector(uint32_t _uiReadAddr);
int drv_flash_write_buffer(uint8_t* _pBuf, uint32_t _uiWriteAddr, uint32_t _usWriteSize);
int drv_flash_read_buffer(uint8_t * _pBuf, uint32_t _uiReadAddr, uint32_t _uiSize);
int drv_flash_register( flash_inf_def flash_inf_t,
						bool (*drv_flash_erase_sector)(uint32_t _uiSectorAddr),
                        bool (*drv_flash_page_write)(uint8_t * _pBuf, uint32_t _uiWriteAddr, uint16_t _usSize),
                        bool (*drv_flash_read_buffer)(uint8_t * _pBuf, uint32_t _uiReadAddr, uint32_t _uiSize),
                        uint32_t (*drv_flash_lock)(void),
                        uint32_t (*drv_flash_unlock)(uint32_t level) );

#endif
